package com.qjc.demo.strategyAndFactory.controller;

import com.qjc.demo.strategyAndFactory.context.StrategyContext;
import com.qjc.demo.strategyAndFactory.service.IStrategyService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName: TestStrategyController
 * @Author: qjc
 * @Date: 2023/5/9 17:46
 */
@RestController
@RequestMapping("/strategy")
public class TestStrategyController {

    @Resource
    private StrategyContext strategyContext;

    /**
     * http://localhost:8081/strategy/test?strategyType=one
     *
     * @param strategyType：one/two/three/four/其他值  根据strategyType执行不同的策略，strategyType可以为空
     * @return
     */
    @RequestMapping("/test")
    public String testStrategy(@RequestParam(name = "strategyType", required = false) String strategyType) {
        IStrategyService strategyService = strategyContext.getStrategyService(strategyType);
        return strategyService.testStrategy();
    }

}
